#include "stdafx.h"
#include "BigInt.h"

using namespace System;
using namespace System::Text;
using namespace System::Collections::Generic;
using namespace Microsoft::VisualStudio::TestTools::UnitTesting;
using namespace APIAL;

namespace BigIntUnitTest
{
	[TestClass]
	public ref class LessThanUnitTest
	{
	private:
		TestContext^ testContextInstance;
		static BigInt *op1;
		static BigInt *op2;
		static BigInt *scratch1;
		static BigInt *result1;
		static BigInt *result2;
		static BigInt *expected;

	public: 
		/// <summary>
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///</summary>
		property Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ TestContext
		{
			Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ get()
			{
				return testContextInstance;
			}
			System::Void set(Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ value)
			{
				testContextInstance = value;
			}
		};

		#pragma region Additional test attributes
		//
		//You can use the following additional attributes as you write your tests:
		//
		//Use ClassInitialize to run code before running the first test in the class
		[ClassInitialize()]
		static void MyClassInitialize(Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ testContext) {
			op1 = new BigInt(3, 8);
			op2 = new BigInt(3, 8);
			result1 = new BigInt(3, 8);
			result2 = new BigInt(3, 8);
			scratch1 = new BigInt(3, 8);
			expected = new BigInt(3, 8);
		}
		//
		//Use ClassCleanup to run code after all tests in a class have run
		[ClassCleanup()]
		static void MyClassCleanup() { 
			delete op1;
			delete op2;
			delete result1;
			delete result2;
			delete scratch1;
			delete expected;
		}
		//
		//Use TestInitialize to run code before running each test
		//[TestInitialize()]
		//void MyTestInitialize() {};
		//
		//Use TestCleanup to run code after each test has run
		//[TestCleanup()]
		//void MyTestCleanup() {};
		//
		#pragma endregion 

		[TestMethod]
		void OneChunkNoOffsetCompare()
		{
			op1->chunks[0] = 0x08;
			op1->normalized = true;
			op1->size = 1;
			op1->positive = true;

			op2->chunks[0] = 0x08;
			op2->normalized = true;
			op2->size = 1;
			op2->positive = true;

			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 0, 3, 3, op2, 0, 3, 3));
			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 0, 4, 4, op2, 0, 3, 3));
			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 0, 3, 3, op2, 0, 4, 4));
			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 0, 5, 5, op2, 0, 4, 4));

			op1->chunks[0] = 0x07;
			op1->normalized = true;
			op1->size = 1;
			op1->positive = true;

			op2->chunks[0] = 0x08;
			op2->normalized = true;
			op2->size = 1;
			op2->positive = true;

			Assert::AreEqual<bool>(true, BigInt::isLessThan(op1, 0, 3, 3, op2, 0, 3, 3));
			Assert::AreEqual<bool>(true, BigInt::isLessThan(op1, 0, 4, 4, op2, 0, 3, 3));
			Assert::AreEqual<bool>(true, BigInt::isLessThan(op1, 0, 3, 3, op2, 0, 4, 4));
			Assert::AreEqual<bool>(true, BigInt::isLessThan(op1, 0, 5, 5, op2, 0, 4, 4));

			op1->chunks[0] = 0x08;
			op1->normalized = true;
			op1->size = 1;
			op1->positive = true;

			op2->chunks[0] = 0x07;
			op2->normalized = true;
			op2->size = 1;
			op2->positive = true;
			
			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 0, 3, 3, op2, 0, 3, 3));
			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 0, 4, 4, op2, 0, 3, 3));
			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 0, 3, 3, op2, 0, 4, 4));
			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 0, 5, 5, op2, 0, 4, 4));
		};

		[TestMethod]
		void TwoChunkNoOffsetCompare()
		{
			op1->chunks[0] = 0x08;
			op1->chunks[1] = 0x53;
			op1->normalized = true;
			op1->size = 2;
			op1->positive = true;

			op2->chunks[0] = 0x08;
			op2->chunks[1] = 0x53;
			op2->normalized = true;
			op2->size = 2;
			op2->positive = true;

			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 1, 7, 14, op2, 1, 7, 14));
			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 1, 7, 14, op2, 1, 7, 14));
			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 1, 7, 14, op2, 1, 7, 14));
			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 1, 7, 14, op2, 1, 7, 14));

			op1->chunks[0] = 0x08;
			op1->chunks[1] = 0x43;
			op1->normalized = true;
			op1->size = 2;
			op1->positive = true;

			op2->chunks[0] = 0x08;
			op2->chunks[1] = 0x53;
			op2->normalized = true;
			op2->size = 2;
			op2->positive = true;

			Assert::AreEqual<bool>(true, BigInt::isLessThan(op1, 1, 7, 14, op2, 1, 7, 14));
			Assert::AreEqual<bool>(true, BigInt::isLessThan(op1, 1, 7, 14, op2, 1, 7, 14));
			Assert::AreEqual<bool>(true, BigInt::isLessThan(op1, 1, 7, 14, op2, 1, 7, 14));
			Assert::AreEqual<bool>(true, BigInt::isLessThan(op1, 1, 7, 14, op2, 1, 7, 14));

			op1->chunks[0] = 0x08;
			op1->chunks[1] = 0x43;
			op1->normalized = true;
			op1->size = 2;
			op1->positive = true;

			op2->chunks[0] = 0x08;
			op2->chunks[1] = 0x13;
			op2->normalized = true;
			op2->size = 2;
			op2->positive = true;

			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 1, 7, 14, op2, 1, 7, 14));
			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 1, 7, 14, op2, 1, 7, 14));
			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 1, 7, 14, op2, 1, 7, 14));
			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 1, 7, 14, op2, 1, 7, 14));
		};

				[TestMethod]
		void ThreeChunkWithOffsetCompare()
		{
			op1->chunks[0] = 0x74;
			op1->chunks[1] = 0x54;
			op1->chunks[2] = 0x54;
			op1->normalized = true;
			op1->size = 3;
			op1->positive = true;

			op2->chunks[0] = 0x58;
			op2->chunks[1] = 0x58;
			op2->chunks[2] = 0x6a;
			op2->normalized = true;
			op2->size = 3;
			op2->positive = true;

			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 2, 4, 11, op2, 2, 4, 11));
			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 2, 4, 11, op2, 2, 4, 11));
			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 2, 4, 11, op2, 2, 4, 11));
			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 2, 4, 11, op2, 2, 4, 11));

			op1->chunks[0] = 0x74;
			op1->chunks[1] = 0x54;
			op1->chunks[2] = 0x54;
			op1->normalized = true;
			op1->size = 3;
			op1->positive = true;

			op2->chunks[0] = 0x4a;
			op2->chunks[1] = 0x29;
			op2->chunks[2] = 0x75;
			op2->normalized = true;
			op2->size = 3;
			op2->positive = true;

			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 2, 4, 11, op2, 2, 3, 11));
			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 2, 4, 11, op2, 2, 3, 11));
			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 2, 4, 11, op2, 2, 3, 11));
			Assert::AreEqual<bool>(false, BigInt::isLessThan(op1, 2, 4, 11, op2, 2, 3, 11));
			Assert::AreEqual<bool>(true, BigInt::isLessThan(op2, 2, 3, 11, op1, 2, 4, 11));
			Assert::AreEqual<bool>(true, BigInt::isLessThan(op2, 2, 3, 11, op1, 2, 4, 11));
			Assert::AreEqual<bool>(true, BigInt::isLessThan(op2, 2, 3, 11, op1, 2, 4, 11));
			Assert::AreEqual<bool>(true, BigInt::isLessThan(op2, 2, 3, 11, op1, 2, 4, 11));
		};
	};
}
